/*
 * scheduler.h
 *
 *  Created on: Mar 11, 2012
 *      Author: Christian
 */

#include <stdbool.h>
#include "queue.h"
#include "enum_scheduler_policy.h"
#include "pcb.h"
#include "process.h"
#include "enum_interrupt_type.h"
#include "cpu.h"

typedef struct scheduler_str {
	Queue aux_q;				//array of pointers to pcbs waiting to be processed by aux io
	Queue key_q;				//queue of pointers to pcbs waiting for keyboard input
//	Queue sema_q;
	pcb** sema_q;				//array of pointers to p/c pcbs that are blocked
//	(pcb*) Node sema_q;
	int sema_q_size;
	int sema_q_start;
	int sema_q_end;
	pcb** ready_q;				//queue of pointers to pcbs that are ready
	int ready_q_start;
	int ready_q_end;
	pcb* curr_pcb;				//pointer to the running pcb
//	process* curr_process;		//pointer to the running process
	sched_type sched_type;				//type of scheduling policy (0=rr, 1=pri, 2=lotto)
	int num_processes;			//used to tell if adts are full and % for circular arrays/queues
} sched;

sched* scheduler_start(sched* sched_ptr, int num_processes, pcb** pcb_array, process** process_array, int sched_type);
void scheduler_init_ready_q(sched* sched_ptr, pcb** pcb_array, process** process_array);
int scheduler_switch_context(int interrupt, sched* sched_ptr, bool* ready_q_status);
void handle_interrupt(int interrupt, sched* sched_ptr, bool* ready_q_status, int semaphore_memory);
